package com.stars.home.activity

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import com.githang.statusbar.StatusBarCompat
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.home.adapter.IncomeAdapter
import com.stars.home.base.MBRActivity
import com.stars.home.config.ConfigRx
import com.stars.home.databinding.ActivityIncomeBinding
import com.stars.home.model.DriverProfit
import com.stars.home.vmodel.IncomeVModel
import com.trailer.base.net.IResp
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch
import com.trailer.base.utils.UiUtils

/**
 * 我的收益-新
 *on 2021/7/19
 */
class IncomeActivity:  MBRActivity<IncomeVModel, IncomeAdapter, ActivityIncomeBinding>() {


    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#00000000"))

        setShow()
        vm.getHeadInfo()
    }

    override fun listeners() {
        super.listeners()
        binding.imgBack.onClick {
            finish()
        }
        binding.butWithdraw.onClick {
            //提现
            UiSwitch.single(this, WithdrawActivity::class.java)

        }

        binding.llWithdrawal.onClick {
            //提现记录
            UiSwitch.single(this, CashListActicity::class.java)

        }
        binding.llPt.onClick {
            //平台
            UiSwitch.bundle(this, PlatformActivity::class.java, B().putString("type","1").ok())
        }
        binding.llJc.onClick {
            //轿车
            UiSwitch.bundle(this, PlatformActivity::class.java, B().putString("type","2").ok())


        }

        binding.imgBut.onClick {
            onRefresh()
        }
    }

    private fun setShow() {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { //不支持沉浸式状态栏
        } else {
            //获取状态栏的高度
            val statusBarHeight: Int = UiUtils.getStatusBarHeight()

            //动态设置高度  tv
            val params = binding.tv.getLayoutParams()
            //获取当前控件的布局对象
            //params.height=UiUtils.dp2dip(getContext(), statusBarHeight);//设置当前控件布局的高度
            params.height = statusBarHeight
            binding.tv.layoutParams = params //将设置好的布局参数应用到控件中
            binding.tv.visibility = View.VISIBLE
        }

    }

    override fun onListReceive(res: IResp<*>) {
        super.onListReceive(res)

        if (null != res) {

            var list = res.data() as List<DriverProfit>
            if (list.isEmpty() && vm.repository().page == 1) {

                binding.listEmpty.visibility = View.VISIBLE
            } else {
                binding.listEmpty.visibility = View.GONE
            }

        }
    }

    override fun vmClass(): Class<IncomeVModel> {
        return IncomeVModel::class.java
    }

    override fun binding(): ActivityIncomeBinding {
       return ActivityIncomeBinding.inflate(layoutInflater)
    }

    override fun initAdapter(): IncomeAdapter {
       return IncomeAdapter(vm)
    }
    override fun title(): String? {
        return null
    }

    override fun transluent(): Boolean {
        return true
    }
    override val isRxbus: Boolean
        get() =true

    @Subscribe(tags = [Tag(ConfigRx.REFRESH_MONEY)])
    fun setRefreshMoney(position: String) {
        vm.getHeadInfo()
    }

}
